package com.qingcheng.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface MemberMapper {
    /**
     * 查询所有成员数据并且带权限
     * @param loginName
     * @param name
     * @return
     */
    @Select("<script>SELECT a.id,login_name,a.STATUS STATUS,NAME,a.delete_id,ar.role_id,DATE_FORMAT(a.create_time,'%Y-%m-%d %H:%i:%s') create_time,ar.id arId FROM tb_admin a\n" +
            "INNER JOIN  tb_admin_role ar\n" +
            "ON ar.admin_id=a.id\n" +
            "INNER JOIN tb_role r\n" +
            "ON ar.role_id=r.id\n" +
            "WHERE a.delete_id=1\n" +
            "AND r.delete_id=1\n"+
            "<if test='loginName!=null and loginName!=\"\"'>and username like '%${username}%'</if>" +
            "<if test='name!=null and name!=\"\"'>and NAME =#{name}</if>"+
            "</script>")
    List<Map>MenberAll(@Param("loginName")String loginName,@Param("name")String name);
    /**
     * 逻辑删除
     */
    @Update("update tb_admin set delete_id=0 where id=#{id}")
    int logicDelete(@Param("id")Integer id);

    /**
     * 修改状态
     */
    @Update("update tb_admin set STATUS=#{STATUS} where id=#{id}")
    int updateStatus(@Param("STATUS")String STATUS,@Param("id")Integer id);

    /**
     * 查看用户所对应id的信息
     */
    @Select("SELECT a.id,a.login_name,a.password,r.name,ar.role_id,ar.id arId FROM `tb_admin`  a\n" +
            "INNER JOIN tb_admin_role ar \n" +
            "ON ar.admin_id=a.id\n" +
            "INNER JOIN tb_role r\n" +
            "ON ar.role_id=r.id\n" +
            "WHERE a.id=#{id}\n" +
            "AND role_id=#{role_id}\n"+
            "AND ar.id=#{arId}"
    )
    Map selecybyid(@Param("id")Integer id,@Param("role_id")Integer role_id,@Param("arId")Integer arId);

    /**
     * 逻辑删除权限
     */
     @Update("update tb_role set delete_id=0 where id=#{id}")
    void deleteIdRole(Integer id);

}
